<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m layui-form" id="form-wisDataGroup-add" autocomplete="off">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>同步组组名：</label>
				<div class="col-sm-4">
					<input id="groupName" name="groupName" class="form-control " type="text" maxlength="64" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="red">*</span>同步数据源：</label>
				<div class="col-sm-4">
					<select id="sourceaId" name="sourceaId" class="form-control sourceaid_select" required>
						<option value="">--请选择--</option>
						<option th:each="entity : ${wisDataSourceList}" th:text="${entity.name}" th:data_name="${entity.name}" th:value="${entity.id}"></option>
					</select>
					<input id="sourceaName" name="sourceaName" type="hidden" >
				</div>
				<label class="col-sm-2 control-label"><span class="red">*</span>目标数据源：</label>
				<div class="col-sm-4">
					<select id="sourcebId" name="sourcebId" class="form-control sourcebid_select" required>
						<option value="">--请选择--</option>
						<option th:each="entity : ${wisDataSourceList}" th:text="${entity.name}" th:data_name="${entity.name}" th:value="${entity.id}"></option>
					</select>
					<input id="sourcebName" name="sourcebName" type="hidden" >
				</div>
			</div>
			
			<div class="form-group layui-form-item">
				<label class="col-sm-2 control-label layui-form-label" for=""><span class="red">*</span>同步表名称：</label>
				<div class="col-sm-4 layui-input-block">
					<select id="tabName" name="tabName" class="form-control" lay-verify="" required lay-search>
						<option value="">--请选择--</option>
					</select>
				</div>
				<label class="col-sm-2 control-label"><span class="red">*</span>目标表名称：</label>
				<div class="col-sm-4">
					<select id="targetName" name="targetName" class="form-control" required>
						<option value="">--请选择--</option>
					</select>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-2 control-label">同步组状态：</label>
				<div class="col-sm-4">
					<label class="radio-box"><input type="radio" value="1" id="state1" name="state">启用</label>
	                <label class="radio-box"><input type="radio" checked value="0" id="state2" name="state">停用</label>
				</div>
				<label class="col-sm-2 control-label"><span class="red">*</span>同步策略：</label>
				<div class="col-sm-4">
	                <select id="syncWay" name="syncWay" class="form-control" required>
						<option value="">--请选择--</option>
						<option value="0">同步表数据写入目标表</option>
						<option value="1">目标表数据写入同步表</option>
						<option value="2">双向写入</option>
					</select>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "quartz/wisDataGroup"
		function submitHandler() {
			if ($.validate.form()) {
				$.operate.save(prefix + "/add", $('#form-wisDataGroup-add').serialize());
			}
		}
		
		$(".sourceaid_select").change( function() {
			var sourceaName = $(this).find("option:selected").text() ;
			$('#sourceaName').val(sourceaName) ;
			var sourceId = $(this).find("option:selected").val() ;
			if (sourceId != "") {
				$.getJSON(prefix+"/queryTabs", { "id" : sourceId }, function(data) {
					var sel = $('#tabName');
					$("#tabName option:not(:first)").remove();
					$.each(data, function(index, obj) {
						var opt = "<option value='"+obj+"' >" + obj + "</option>";
						sel.append(opt);
					});
				})
			}
		})
		
		$(".sourcebid_select").change( function() {
			var sourcebName = $(this).find("option:selected").text() ;
			$('#sourcebName').val(sourcebName) ;
			var sourceId = $(this).find("option:selected").val() ;
			if (sourceId != "") {
				$.getJSON(prefix+"/queryTabs", { "id" : sourceId }, function(data) {
					var sel = $('#targetName');
					$("#targetName option:not(:first)").remove();
					$.each(data, function(index, obj) {
						var opt = "<option value='"+obj+"' >" + obj + "</option>";
						sel.append(opt);
					});
				})
			}
		})
	</script>
</body>
</html>
